<?php
require_once '../classes/TestDataManager.php';
require_once '../classes/InitPropertiesDataManager.php';
require_once '../classes/ConnectionDB.php';
require_once '../bean/InitProperties.php';
require_once '../classes/LoadProperties.php';

$properties= new LoadProperties();

$properties->initServices();
$connection =ConnectionDB::getInstance()->connectToDB();

$initProperties = InitPropertiesDataManager::getInstance()->getInitProperties($connection);

$ftp_host = $initProperties["ftpHost"];

$connect = ftp_connect($ftp_host) or die("Si è verificato un errore durante la connessione al server ftp");

/* login al server ftp */

$username = $initProperties["ftpUsername"];

$pwd = $initProperties["ftpPassword"];

$login = ftp_login($connect, $username, $pwd) or die("Si è verificao un errore durante l'accesso al server ftp");

echo 'connessione ftp stailita';

$pathfile= $properties->getUploadPath().'/' . $_POST["nomeFile"];

echo ' pathfil ' . str_replace("http://", "", $pathfile);
if(ftp_delete($connect, str_replace("http://", "", $pathfile)))
{
    echo 'delete ok';
    ftp_quit($connect) or die("Si è verificato un errore durante la chiusura della connessione al server ftp");
    $codiceDomanda=$_POST["code"];
    TestDataManager::getInstance()->deleteLinkFromQuestion($connection, $codiceDomanda);
    $str="detailQuestion.php?codiceDomanda=" . $codiceDomanda;
    header("Location:".$str);
    
}

?>
